package com.yonyou.train.web;

import com.yonyou.train.Message;
import com.yonyou.train.ResultJson;
import com.yonyou.train.StatusCode;
import com.yonyou.train.model.Auth;
import com.yonyou.train.model.User;
import com.yonyou.train.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RestController
@RequestMapping(value = "/auths")
public class AuthController {
    @Autowired
    private AuthService authService;

    static Map<Long, Auth> auths = Collections.synchronizedMap(new HashMap<Long, Auth>());

    @RequestMapping(value="/", method=RequestMethod.GET)
    public Object doQueryAuth() {
        List<Map> list=authService.queryAuth();

        return ResultJson.success(StatusCode.SUCCESS,"success",list);
    }

    @RequestMapping(value="/user", method=RequestMethod.GET)
    public Object doQueryUserAuth(HttpServletRequest request) {
        String usrid = request.getHeader("token");
        Auth auth=authService.queryUserAuth(usrid);

        return ResultJson.success(StatusCode.SUCCESS,"success",auth);
    }



    @RequestMapping(value="/update", method=RequestMethod.POST)
    public Object doUpdateAuth(@RequestBody Map map) {
        authService.updateAuth(map);
        return ResultJson.success(StatusCode.SUCCESS,"success","更新成功");
    }


}
